package prefrenceareaservicelogic

import (
	"context"

	"github.com/blog-zero/rpc/cms/cmsclient"
	"github.com/blog-zero/rpc/cms/internal/svc"
	"github.com/blog-zero/rpc/model/cmsmodel"

	"github.com/zeromicro/go-zero/core/logx"
)

type PrefrenceAreaAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewPrefrenceAreaAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PrefrenceAreaAddLogic {
	return &PrefrenceAreaAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 商品优选
func (l *PrefrenceAreaAddLogic) PrefrenceAreaAdd(in *cmsclient.PrefrenceAreaAddReq) (*cmsclient.PrefrenceAreaAddResp, error) {
	item := &cmsmodel.CmsPrefrenceArea{
		Name:       in.Name,
		SubTitle:   in.SubTitle,
		Pic:        in.Pic,
		Sort:       in.Sort,
		ShowStatus: in.ShowStatus,
	}
	if _, err := l.svcCtx.CmsPrefrenceAreaModel.Insert(l.ctx, item); err != nil {
		return nil, err
	}

	return &cmsclient.PrefrenceAreaAddResp{}, nil
}
